package net.sos.services.client;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import javax.activation.DataHandler;
import javax.activation.FileDataSource;

import net.sos.services.contract.IFirstService;
import net.sos.services.valueobject.Message;

import org.apache.commons.io.IOUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class FirstServiceClient {

   public static void main(final String[] args) throws IOException {
      ApplicationContext ctx = new ClassPathXmlApplicationContext(
            "net/sos/services/config/cxf-client.xml");
      IFirstService firstClient = (IFirstService) ctx.getBean("firstClient");
      Message outMessage = firstClient.giveOneGetN(getInMessage());
//      System.out.println(IOUtils.readLines((InputStream) outMessage
//            .getContent().getContent()));
   }

   private static Message getInMessage() {
      Message message = new Message();
      message.setRepeatCount((byte) 2);
      FileDataSource fds = new FileDataSource(new File("c:/a.txt"));
      message.setContent(new DataHandler(fds));
      return message;
   }

}
